﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Diagnostics;

namespace TrenchcoatRobots.Classes.Components {
	/// <summary>
	/// TextureRenderer renders a texture to the screen according to the angle & position of the base object.
	/// </summary>
	class TextureRenderer : Component {
		public Texture2D Texture { get; set; }

		#region Constructors
		/// <summary>
		/// Creates a new TexturedObject at 0,0 with the rotation 0.
		/// </summary>
		/// <param name="gameObject">The GameObject to which the Rigidbody will belong.</param>
		/// <param name="texture">Texture for the TexturedObject</param>
		public TextureRenderer( GameObject gameObject, Texture2D texture )
			: base( gameObject, "TextureRenderer", false ) {
			this.Texture = texture;
		}
		#endregion

		public override void Draw( ref SpriteBatch spriteBatch, ref TrenchcoatRobots.Datatypes.DrawInfo drawinfo ) {
			spriteBatch.Begin();
			spriteBatch.Draw(
				Texture,
				( Parent.Position + drawinfo.Camera.Position ) * drawinfo.Camera.Zoom,
				new Rectangle( 0, 0, Texture.Width, Texture.Height ),
				Color.White,
				MathHelper.ToRadians( Parent.Angle ),
				new Vector2( Texture.Width, Texture.Height ) * 0.5f,
				1.0f * drawinfo.Camera.Zoom,
				SpriteEffects.None,
				0f
				);
			spriteBatch.End();
		}
	}
}
